angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'starter.filters', 'starter.directives'])
    .run(['$ionicPlatform', '$rootScope', '$location', function ($ionicPlatform, $rootScope, $location) {
        $ionicPlatform.ready(function () {
            if (window.cordova && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            }
            if (window.StatusBar) {
                StatusBar.styleDefault();
            }
        });

        $rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) {
            //刷新的时候前后的url是一样的，当刷新界面则进入首页
            if (newUrl == oldUrl) {
                $location.url("/tab/home");
            }
        });
    }])
    .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('tab', {
                url: "/tab",
                abstract: true,
                templateUrl: "/templates/tabs"
            })

            .state('tab.home', {
                url: '/home',
                views: {
                    'tab-home': {
                        templateUrl: '/templates/tab/home',
                        controller: 'HomeCtrl'
                    }
                }
            })

            .state('tab.mybattles', {
                url: '/mybattles',
                views: {
                    'tab-mybattles': {
                        templateUrl: '/templates/tab/mybattles',
                        controller: 'MyBattlesCtrl'
                    }
                }
            })

            //发送挑战信
            .state('tab.mybattles-newletter', {
                url : '/mybattles/newletter',
                views : {
                    'tab-mybattles': {
                        templateUrl: '/templates/tab/mybattles/newletter',
                        controller: 'NewLetterCtrl'
                    }
                }
            })

            .state('tab.mybattles-newletter-storeId', {
                url : '/mybattles/newletter/:storeId',
                views : {
                    'tab-mybattles': {
                        templateUrl: '/templates/tab/mybattles/newletter',
                        controller: 'NewLetterCtrl'
                    }
                }
            })

            //收件箱
            .state('tab.mybattles-inbox', {
                url: '/mybattles/inbox',
                views: {
                    'tab-mybattles': {
                        templateUrl: '/templates/tab/mybattles/inbox',
                        controller: 'MyBattlesCtrl'
                    }
                }
            })

            //发件箱
            .state('tab.mybattles-outbox', {
                url: '/mybattles/outbox',
                views: {
                    'tab-mybattles': {
                        templateUrl: '/templates/tab/mybattles/outbox',
                        controller: 'MyBattlesCtrl'
                    }
                }
            })

            //题库信息 界面
            .state('tab.store-detail', {
                url: '/store/:storeId',
                views: {
                    'tab-home': {
                        templateUrl: '/templates/tab/store/detail',
                        controller: 'StoreCtrl'
                    }
                }
            })

            //对战界面
            .state('tab.battle-detail', {
                url: '/battle/:battleId',
                views: {
                    'tab-home': {
                        templateUrl: '/templates/tab/battle/detail',
                        controller: 'BattleCtrl'
                    }
                }
            })

            //练习界面
            .state('tab.practice-detail', {
                url: '/practice/:practiceId',
                views: {
                    'tab-home': {
                        templateUrl: '/templates/tab/practice/detail',
                        controller: 'PracticeCtrl'
                    }
                }
            })

            .state('tab.honor', {
                url: '/honor',
                views: {
                    'tab-honor': {
                        templateUrl: '/templates/tab/honor',
                        controller: 'HonorCtrl'
                    }
                }
            })

            .state('tab.other', {
                url: '/other',
                views: {
                    'tab-other': {
                        templateUrl: '/templates/tab/other',
                        controller: 'OtherCtrl'
                    }
                }
            })
            //游戏规则
            .state('tab.other-manual', {
                url : '/other/manual',
                views : {
                    'tab-other' : {
                        templateUrl : '/templates/tab/other/manual',
                        controller:'OtherCtrl'
                    }
                }
            });

        $urlRouterProvider.otherwise('/tab/home');
    }]);
